<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>`
    <button id="btn2">直接使用axios发起GET请求</button>
    <script>
       document.querySelector('#btn2').addEventListener('click',function(){
        const url = 'http://www.liulongbin.top:3006/api/get'
        const paramsdata = {name:'晋华翼',age:20}
        axios({
            method:'GET',
            url:url,
            //查询参数
            params:paramsdata
        }).then(function(res){
            console.log(res.data)
        })
        })
    </script>
    <button id="btn3">直接使用axios发起POST请求</button>
    <script>
        document.querySelector('#btn2').addEventListener('click',function(){
        axios({
            method:'POST',
            url:'http://www.liulongbin.top:3006/api/post',
            data:{
                name:'娃哈哈',
                age:10
            }
            
        }).then(function(res){
            console.log(res.data)
        }).catch(error=>{
            console.log(error.response.data.message);
        })
        })
    </script>

</body>
</html>
